# import os
# import time
#
# from moviepy.video.io.VideoFileClip import VideoFileClip
#
#
# def split_video(video_path):
#     file_name = os.path.basename(video_path)
#     file_name_prefix = file_name.split(".")[0]
#     file_name_suffix = file_name.split(".")[-1]
#     clip = VideoFileClip(video_path)
#     total_duration = clip.duration
#     segment_duration = 2 * 60  # 2 minutes in seconds
#     for i in range(0, int(total_duration), segment_duration):
#         start = i
#         end = min(i + segment_duration, total_duration)
#         segment = clip.subclip(start, end)
#         output_path = final_file + file_name_prefix + str(i) + '.' + file_name_suffix
#         if file_name_suffix == 'mp4':
#             segment.write_videofile(output_path)
#         elif file_name_suffix == 'mkv':
#             segment.write_videofile(output_path, codec='libx264')
#
#
# def get_all_files(folder_path):
#     file_paths = []
#     for root, dirs, files in os.walk(folder_path):
#         for file in files:
#             file_paths.append(os.path.join(root, file))
#     return file_paths
#
#
# if __name__ == '__main__':
#     '''
#     pip install moviepy
#     视频文件分割成每2分钟一个
#     '''
#     # 需要分割的视频文件
#     need_convert_file = 'D:\\新建文件夹\\'
#     # 分割完成的视频文件
#     final_file = 'D:\\新建文件夹 (2)\\'
#     print('开始')
#     timestamp = int(time.time())
#     for final_pash in get_all_files(need_convert_file):
#         split_video(final_pash)
#     endTime = int(time.time())
#     print('结束   一共用时: ' + str(endTime - timestamp) + ' 秒')
